home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / e / capus2.lha / capus2 / WhatView / Sources / WhatIs.e < prev    next >
Encoding:
Text File  |  1995-03-27  |  5.0 KB  |  171 lines

  1. /*======<<< Peps Header >>>======
  2.  PRGVERSION '0'
  3.  ================================
  4.  PRGREVISION '1'
  5.  ================================
  6.  AUTHOR      'NasGûl'
  7.  ===============================*/
  8.  
  9. OPT OSVERSION=37
  10.  
  11. CONST MAXPATH=250
  12.  
  13. ENUM ER_NONE,ER_BADARGS,ER_NOPORT,ER_PORT,ER_ARG
  14.  
  15. MODULE 'dos/dos','dos/dosasl','utility'
  16. MODULE 'eropenlib','exec/ports','exec/nodes','wvprefs'
  17. DEF whatviewport:PTR TO mp
  18. DEF dummyport:PTR TO mp
  19. DEF action[256]:STRING
  20. DEF file=FALSE
  21. /*"main()"*/
  22. PROC main() HANDLE 
  23.     DEF myarg:PTR TO LONG,rdargs=NIL
  24.     DEF dirw[100]:STRING,fib:fileinfoblock
  25.     DEF lock
  26.     VOID {banner}
  27.     myarg:=[0,0,0,0]
  28.     IF (utilitybase:=OpenLibrary('utility.library',37))=NIL THEN Raise(ER_UTILITYLIB)
  29.     IF (whatviewport:=FindPort('WhatViewPort'))=NIL THEN Raise(ER_NOPORT)
  30.     IF (dummyport:=CreateMsgPort())=NIL THEN Raise(ER_PORT)
  31.     IF rdargs:=ReadArgs('DOSSIER,ACT/K,FLUSH/S,PREFS/S',myarg,NIL)
  32.         IF myarg[2]
  33.             p_SendWhatviewMessage('FLUSH',0)
  34.             Raise(ER_NONE)
  35.         ENDIF
  36.         IF myarg[3]
  37.             p_SendWhatviewMessage('PREFS',0)
  38.             Raise(ER_NONE)
  39.         ENDIF
  40.         IF myarg[1] 
  41.             StrCopy(action,myarg[1],ALL)
  42.             UpperStr(action)
  43.         ELSE
  44.             StrCopy(action,'WHATVIEW',ALL)
  45.         ENDIF
  46.         IF StrCmp(action,'QUIT',4)
  47.             p_SendWhatviewMessage('QUIT',0)
  48.             Raise(ER_NONE)
  49.         ENDIF
  50.         IF myarg[0]
  51.             StrCopy(dirw,myarg[0],ALL)
  52.         ELSE
  53.             Raise(ER_ARG)
  54.         ENDIF
  55.         IF lock:=Lock(dirw,-2)
  56.             IF Examine(lock,fib)
  57.                 IF fib.direntrytype>0
  58.                     IF myarg[4] THEN NOP ELSE AddPart(dirw,'#?',100)
  59.                     file:=FALSE
  60.                 ELSE
  61.                     file:=TRUE
  62.                 ENDIF
  63.             ENDIF
  64.             UnLock(lock)
  65.             p_RecDir(dirw)
  66.             Raise(ER_NONE)
  67.         ELSE
  68.             p_RecDir(dirw)
  69.             Raise(ER_BADARGS)
  70.         ENDIF
  71.     ELSE
  72.         Raise(ER_BADARGS)
  73.     ENDIF
  74. EXCEPT
  75.     IF rdargs THEN FreeArgs(rdargs)
  76.     IF dummyport THEN DeleteMsgPort(dummyport)
  77.     IF utilitybase THEN CloseLibrary(utilitybase)
  78.     SELECT exception
  79.         CASE ER_BADARGS;    WriteF('Mauvais Arguments.\n')
  80.         CASE ER_UTILITYLIB; WriteF('Utility.library v37+ ?.\n')
  81.         CASE ER_NOPORT;     WriteF('Port WhatViewPort inexistant.\n')
  82.         CASE ER_PORT;       WriteF('Impossible de créer un port de message.\n')
  83.         CASE ER_ARG;        WriteF('1 Argument manquant (Dossier ou Fichier ou Pattern).\n')
  84.     ENDSELECT
  85. ENDPROC
  86. /**/
  87. /*"p_RecDir(dirr)"*/
  88. PROC p_RecDir(dirr) HANDLE
  89.   DEF er,i:PTR TO fileinfoblock,size=0,anchor=NIL:PTR TO anchorpath,fullpath
  90.   DEF rdir[100]:STRING,reelname[256]:STRING
  91.   DEF ma:PTR TO achain,ii:PTR TO fileinfoblock
  92.       anchor:=New(SIZEOF anchorpath+MAXPATH)
  93.       anchor.breakbits:=4096
  94.       anchor.strlen:=MAXPATH-1
  95.       er:=MatchFirst(dirr,anchor)                   /* collect all strings */
  96.       IF er=ERROR_NO_MORE_ENTRIES THEN JUMP exit
  97.       WHILE er=0
  98.         IF CtrlC() THEN JUMP exit
  99.         fullpath:=anchor+SIZEOF anchorpath
  100.         i:=anchor.info
  101.         ma:=anchor.base
  102.         ii:=ma.info
  103.         NameFromLock(ma.lock,rdir,256)
  104.         /*
  105.         WriteF('*********** \s \d\n',ii.filename,ii.direntrytype)
  106.         WriteF('DirEntryType: \d RDir \s ReelName \s\n',i.direntrytype,rdir,i.filename)
  107.         */
  108.         StringF(reelname,'\s',i.filename)
  109.         p_SendWhatviewMessage(reelname,rdir)
  110.         er:=MatchNext(anchor)
  111.     ENDWHILE
  112.   exit:
  113.   p_DoAction()
  114.   IF er<>ERROR_NO_MORE_ENTRIES THEN Raise(er)
  115.   MatchEnd(anchor)
  116.   Dispose(anchor)
  117.   anchor:=NIL
  118.   Raise(ER_NONE)
  119. EXCEPT                                  /* nested exception handlers! */
  120.   IF anchor THEN MatchEnd(anchor)
  121.   Raise(exception)  /* this way, we call _all_ handlers in the recursion  */
  122. ENDPROC size        /* and thus calling MatchEnd() on all hanging anchors */
  123. /**/
  124. /*"p_SendWhatviewMessage(name,curdir)"*/
  125. PROC p_SendWhatviewMessage(name,curdir) HANDLE 
  126.     DEF execmsg:PTR TO mn
  127.     DEF mymsg:PTR TO wvmsg
  128.     DEF node:PTR TO ln
  129.     DEF rmsg
  130.     mymsg:=New(SIZEOF wvmsg)
  131.     execmsg:=mymsg
  132.     node:=execmsg
  133.     node.type:=NT_MESSAGE
  134.     node.pri:=0
  135.     execmsg.replyport:=dummyport
  136.     mymsg.name:=name
  137.     IF curdir<>0 THEN mymsg.lock:=Lock(curdir,-2)
  138.     Forbid()
  139.     IF whatviewport
  140.         PutMsg(whatviewport,mymsg)
  141.     ENDIF
  142.     Permit()
  143.     IF whatviewport
  144.         WaitPort(dummyport)
  145.         rmsg:=GetMsg(dummyport)
  146.     ENDIF
  147.     Raise(ER_NONE)
  148. EXCEPT
  149.     IF curdir<>0
  150.         IF mymsg.lock THEN UnLock(mymsg.lock)
  151.     ENDIF
  152.     IF mymsg THEN Dispose(mymsg)
  153. ENDPROC
  154. /**/
  155. /*"p_DoAction()"*/
  156. PROC p_DoAction()
  157.   IF StrCmp(action,'WHATVIEW',8)
  158.       p_SendWhatviewMessage('WHATVIEW',0)
  159.   ELSEIF StrCmp(action,'INFO',4)
  160.       p_SendWhatviewMessage('INFO',0)
  161.   ELSEIF StrCmp(action,'ADDICON',7)
  162.       p_SendWhatviewMessage('ADDICON',0)
  163.   ELSEIF StrCmp(action,'EXECUTE',7)
  164.       p_SendWhatviewMessage('EXECUTE',0)
  165.   ELSEIF StrCmp(action,'QUIT',4)
  166.       p_SendWhatviewMessage('QUIT',0)
  167.   ENDIF
  168. ENDPROC
  169. /**/
  170.  
  171.